package org.dromara.wms.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.web.core.BaseService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.wms.domain.WmsStockLog;
import org.dromara.wms.service.WmsStockLogService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 出入库记录台账
 *
 * @author wenrui Su
 * @date 2024-05-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wms/stockLog")
public class WmsStockLogController extends BaseService {

  private final WmsStockLogService wmsStockLogService;

/**
 * 查询出入库记录台账列表
 */
@SaCheckPermission("wms:stockLog:list")
@GetMapping("/list")
  public TableDataInfo<WmsStockLog> list(WmsStockLog bo, PageQuery pageQuery) {
    return wmsStockLogService.queryPageList(bo, pageQuery);
  }

  /**
   * 导出出入库记录台账列表
   */
  @SaCheckPermission("wms:stockLog:export")
  @Log(title = "出入库记录台账", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(WmsStockLog bo, HttpServletResponse response) {
    List<WmsStockLog> list = wmsStockLogService.queryList(bo);
    ExcelUtil.exportExcel(list, "出入库记录台账", WmsStockLog. class,response);
  }

  /**
   * 获取出入库记录台账详细信息
   *
   * @param id 主键
   */
  @SaCheckPermission("wms:stockLog:query")
  @GetMapping("/{id}")
  public R<WmsStockLog> getInfo(@NotNull(message = "主键不能为空")
                                 @PathVariable Long id) {
    return R.ok(wmsStockLogService.queryById(id));
  }

  /**
   * 新增出入库记录台账
   */
  @SaCheckPermission("wms:stockLog:add")
  @Log(title = "出入库记录台账", businessType = BusinessType.INSERT)
  @RepeatSubmit()
  @PostMapping()
  public R<Void> add(@Validated(AddGroup.class) @RequestBody WmsStockLog bo) {
    return toAjax(wmsStockLogService.insertByBo(bo));
  }

  /**
   * 修改出入库记录台账
   */
  @SaCheckPermission("wms:stockLog:edit")
  @Log(title = "出入库记录台账", businessType = BusinessType.UPDATE)
  @RepeatSubmit()
  @PutMapping()
  public R<Void> edit(@Validated(EditGroup.class) @RequestBody WmsStockLog bo) {
    return toAjax(wmsStockLogService.updateByBo(bo));
  }

  /**
   * 删除出入库记录台账
   *
   * @param ids 主键串
   */
  @SaCheckPermission("wms:stockLog:remove")
  @Log(title = "出入库记录台账", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public R<Void> remove(@NotEmpty(message = "主键不能为空")
                        @PathVariable Long[] ids) {
    return toAjax(wmsStockLogService.deleteWithValidByIds(List.of(ids), true));
  }
}
